package model

import "myserver/app/types"

func CreateClassificationTable() {
	p := &types.TableClassification{}
	tables = append(tables, *p)
}

// AddClassification 添加一个分类
func AddClassification(m *types.TableClassification) error {
	var err error
	tx := db.Begin()
	if err = tx.Create(m).Error; err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()
	return err
}

// FindClassificationByUuid 根据uuid 查询
func FindClassificationByUuid(strs []string) ([]types.TableClassification, error) {
	var data []types.TableClassification
	var err error
	tx := db.Begin()
	err = tx.Where("uuid IN ? AND is_del=?", strs, 0).Find(&data).Error
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()
	}

	return data, err
}

// 更新分类
func UpDataClassification(list *[]types.TableClassification) error {
	tx := db.Begin()
	err := tx.Save(list).Error
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()
	}
	return err
}
